using System;
using System.ComponentModel.DataAnnotations;
using SqlSugar;

namespace Domain
{
    /// <summary>
    /// 审批历史记录实体类
    /// 用于记录业务对象的审批流程历史
    /// </summary>
    [SugarTable("ApprovalHistories")]
    public class ApprovalHistory
    {
        /// <summary>
        /// 审批历史记录的唯一标识符
        /// </summary>
        [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
        public int Id { get; set; }
        
        /// <summary>
        /// 业务对象ID
        /// 关联到被审批的业务对象（如采购订单、销售订单等）
        /// </summary>
        [Required]
        public int BusinessId { get; set; }
        
        /// <summary>
        /// 业务类型
        /// 标识业务对象的类型（如PurchaseOrder、SalesOrder等）
        /// </summary>
        [Required, StringLength(50)]
        public string BusinessType { get; set; }
        
        /// <summary>
        /// 工作流ID
        /// 关联到Workflow表
        /// </summary>
        [Required]
        public int WorkflowId { get; set; }
        
        /// <summary>
        /// 工作流步骤ID
        /// 关联到WorkflowStep表
        /// </summary>
        public int? StepId { get; set; }
        
        /// <summary>
        /// 审批动作
        /// 如：提交、批准、拒绝、退回等
        /// </summary>
        [Required, StringLength(50)]
        public string Action { get; set; }
        
        /// <summary>
        /// 执行审批的用户ID
        /// </summary>
        [Required, StringLength(50)]
        public string ApprovedBy { get; set; }
        
        /// <summary>
        /// 审批时间
        /// </summary>
        [Required]
        public DateTime ApprovalTime { get; set; }
        
        /// <summary>
        /// 审批意见
        /// </summary>
        [StringLength(500)]
        public string Comments { get; set; }
        
        /// <summary>
        /// 审批前状态
        /// </summary>
        [StringLength(50)]
        public string PreviousStatus { get; set; }
        
        /// <summary>
        /// 审批后状态
        /// </summary>
        [StringLength(50)]
        public string NewStatus { get; set; }
        
        /// <summary>
        /// 审批级别
        /// </summary>
        public int ApprovalLevel { get; set; }
        
        /// <summary>
        /// 关联的工作流实例
        /// </summary>
        [Navigate(NavigateType.OneToOne, nameof(WorkflowId))]
        public virtual Workflow Workflow { get; set; }
        
        /// <summary>
        /// 关联的工作流步骤
        /// </summary>
        [Navigate(NavigateType.OneToOne, nameof(StepId))]
        public virtual WorkflowStep Step { get; set; }
        
        /// <summary>
        /// 默认构造函数
        /// </summary>
        public ApprovalHistory()
        {
            ApprovalTime = DateTime.Now;
        }
    }
}